package com.javaweb.controller;

/**
 * @desc:
 * @author: jzy
 * @date: 2024/10/22 23:01
 */

import com.javaweb.common.ResponseResult;
import com.javaweb.model.Article;
import com.javaweb.service.ArticleService;
import com.javaweb.service.dto.ArticleConditionDto;
import com.javaweb.service.dto.ArticleDto;
import com.javaweb.service.dto.ArticleUpdateDto;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * todo: 文章管理模块
 */
@RestController
@RequestMapping("/blog-api/v0.1/article")
public class ArticleController {
private ArticleService articleService;
    @PostMapping("/list")
    public ResponseResult<List<Article>> list(@RequestBody ArticleConditionDto articleCond) {
        // 根据条件查询文章

        List<Article> articles = articleService.listArticles(articleCond);
        return ResponseResult.ok(articles);
    }

    @PostMapping("/add")
    public ResponseResult add(@RequestBody ArticleDto articleDto) {
        // 添加新文章
        articleService.addArticle(articleDto);
        return ResponseResult.ok("文章添加成功");
    }

    @PostMapping("/update")
    public ResponseResult<Void> update(@RequestBody ArticleUpdateDto articleUpdateDto) {
        // 更新文章
        articleService.updateArticle(articleUpdateDto);
        return ResponseResult.ok(null);
    }

    @GetMapping("/publish")
    public ResponseResult<Void> publish(@PathVariable String articleId) {
        // 发布文章
        articleService.publishArticle(articleId);
        return ResponseResult.ok(null);
    }
}
